package com.hongxun.design.utils.soundUtil;

import android.content.Context;
import android.os.Environment;

import com.hongxun.design.mytools.ToastShow;


/**
 * Created by zerdoor_pc on 2016/4/21.
 */
public class SoundUtil {
    private URecorder recorder;
    private UPlayer player;
    private static  SoundUtil intence;
    private Context context;
    private String path;
    public   SoundUtil(Context context,String path) {
        if (path.length()==0){
            path = Environment.getExternalStorageDirectory().getAbsolutePath();
            path += "/ione.pcm";
            this.path=path;
        }
        this.context=context;
        recorder =URecorder.getIntence(path);
        player = UPlayer.getIntence(path);
    }

    public static SoundUtil getIntence(Context context,String path){
        if (intence==null){
            intence=new SoundUtil(context,path);
        }
        return intence;
    }
    public void startRecod() {
        ToastShow.showShort(context, "start record");
        recorder.start();
    }

    public void stopRecod() {
        ToastShow.showShort(context, "stop record");
        recorder.stop();
    }


    public void startPlay() {
        ToastShow.showShort(context, "start play");
        if (player==null)player = UPlayer.getIntence(path);
        player.start();
    }

    public void stopPlay() {
        ToastShow.showShort(context, "stop play");
        if (player==null)player = UPlayer.getIntence(path);
        player.stop();
    }


}
